home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / croutes.zip / BIOSIO.ASM next >
Assembly Source File  |  1984-06-25  |  13KB  |  536 lines

  1. ;                         *** biosio.asm ***
  2. ;
  3. ; IBM-PC microsoft "C" under PC-DOS v2.00
  4. ;
  5. ; MICROSOFT "C" callable 8088 assembly routines that interface directly
  6. ; with the basic I/O system (BIOS).
  7. ;
  8. ; NOTE -- The IBM Technical Reference Manual contains a listing of the
  9. ;         BIOS and more complete descriptions of each interrupt.
  10. ;
  11. ; Written by L. Cuthbertson, April 1984
  12. ;
  13. ;**********************************************************************
  14. ;
  15. PGROUP    GROUP    PROG
  16. PROG    SEGMENT    BYTE PUBLIC 'PROG'
  17.  
  18.     PUBLIC    KEYRD,KEYHIT,KEYSHIF
  19.  
  20.     PUBLIC    BIOSINI,BIOSSET,BIOSPOS
  21.     PUBLIC    BIOSUP,BIOSDWN,BIOSRCA,BIOSWCA,BIOSWC
  22.     PUBLIC    BIOSWD,BIOSTTY,BIOSCUR
  23.  
  24.     PUBLIC    COMINI,COMOUT,COMIN,COMSTAT
  25.  
  26.     PUBLIC    INP,OUTP
  27.  
  28.     ASSUME    CS:PGROUP
  29. ;
  30. ;**********************************************************************
  31. ;
  32. ;                        *** KEYBOARD I/O ***
  33. ;
  34. ; NOTE - Keyboard interrupt description starts on page A-23 of Tech
  35. ;        Ref Manual.
  36. ;
  37. ;**********************************************************************
  38. ;
  39. ; Read a keyboard entry - wait for entry if one not ready.
  40. ;
  41. ; synopsis    c = keyrd();
  42. ;
  43. ;        int c;        high order bits contain scan code
  44. ;                low order bits contain character
  45. ;
  46. ; NOTE - Scan codes are described on page 2-17 of the Technical
  47. ;        Reference Manual.
  48. ;
  49. KEYRD    PROC    NEAR
  50.     PUSH    BP
  51.     MOV    BP,SP
  52.     MOV    AH,0        ; READ NEXT CHARACTER ENTERED
  53.     INT    16H        ; BIOS KEYBOARD I/O INTERRUPT
  54.     POP    BP
  55.     RET
  56. KEYRD    ENDP
  57. ;
  58. ; Check to see if there is a character in the keyboard buffer.
  59. ;
  60. ; synopsis    iret = keyhit();
  61. ;
  62. ;        int iret;    = 0 if no character availible
  63. ;                = 1 character is availible
  64. ;
  65. KEYHIT    PROC    NEAR
  66.     PUSH    BP
  67.     MOV    BP,SP
  68.     MOV    AH,1        ; CHECK KEYBOARD BUFFER FUNCTION
  69.     INT    16H        ; BIOS KEYBOARD I/O INTERRUPT
  70.     MOV    AX,0        ; ASSUME THAT NO CHARACTER READY
  71.     JZ    K1
  72.     MOV    AX,1        ; CHARACTER READY
  73. K1:
  74.     POP    BP
  75.     RET
  76. KEYHIT    ENDP
  77. ;
  78. ; Check to see what the shift key status is.
  79. ;
  80. ; synopsis    iret = keyshif();
  81. ;
  82. ;        int iret;       shift key status
  83. ;
  84. ;            0x80 = insert state is active
  85. ;            0x40 = cap lock state has been toggled
  86. ;            0x20 = num lock state has been toggled
  87. ;            0x10 = scroll lock state has been toggled
  88. ;            0x08 = alternate shift key depressed
  89. ;            0x04 = control shift key depressed
  90. ;            0x02 = left shift key depressed
  91. ;            0x01 = right shift key depressed
  92. ;
  93. ; NOTE - from page A-2 and A-3 of Tech Ref Manual
  94. ;
  95. KEYSHIF    PROC    NEAR
  96.     PUSH    BP
  97.     MOV    BP,SP
  98.     MOV    AH,2        ; CHECK SHIFT STATUS FUNCTION
  99.     INT    16H        ; BIOS KEYBOARD I/O INTERRRUPT
  100.     POP    BP
  101.     RET
  102. KEYSHIF    ENDP
  103. ;
  104. ; *********************************************************************
  105. ;
  106. ;            *** VIDEO I/O ***
  107. ;
  108. ; NOTE - the video I/O interrupt description starts on page A-43 of the
  109. ;        Tech Ref Manual.
  110. ;
  111. ; *********************************************************************
  112. ;
  113. ; Initialize screen I/O using the BIOS set mode call
  114. ;
  115. ; synopsis    biosini(stype);
  116. ;
  117. ;        int stype;    screen type
  118. ;
  119. ;            0 = 40x25 BW (power on default)
  120. ;            1 = 40x25 Color
  121. ;            2 = 80x25 BW
  122. ;            3 = 80x25 Color
  123. ;            graphics mode
  124. ;            4 = 320x200 Color
  125. ;            5 = 320x200 BW
  126. ;            6 = 640x200 BW
  127. ;            internal use only
  128. ;            7 = 80x25 BW card
  129. ;
  130. BIOSINI    PROC    NEAR
  131.     PUSH    BP
  132.     MOV    BP,SP
  133.     MOV    AL,[BP+4]    ; SCREEN TYPE IN AL
  134.     MOV    AH,0        ; SET MODE FUNCTION
  135.     INT    10H        ; BIOS VIDEO I/O INTERRUPT
  136.     POP    BP
  137.     RET
  138. BIOSINI    ENDP
  139. ;
  140. ; Set the current cursor position.
  141. ;
  142. ; synopsis    biosset(irow,icol);
  143. ;
  144. ;        *** no value returned ***
  145. ;        int irow;    0 to 24
  146. ;        int icol;    0 to 79
  147. ;
  148. BIOSSET    PROC    NEAR
  149.     PUSH    BP
  150.     MOV    BP,SP
  151.     MOV    DH,[BP+4]    ; ROW
  152.     MOV    DL,[BP+6]    ; COLUMN
  153.     MOV    BH,0        ; CURRENT PAGE NUMBER
  154.     MOV    AH,2        ; CURSOR POSITION SET FUNTION NUMBER
  155.     INT    10H        ; VIDEO I/O INTERRUPT
  156.     POP    BP
  157.     RET
  158. BIOSSET    ENDP
  159. ;
  160. ; Return the current cursor postion.
  161. ;
  162. ; synopsis    iret = biospos();
  163. ;
  164. ;        int iret;    high order bits contain row
  165. ;                low order bits contain column
  166. ;
  167. BIOSPOS    PROC    NEAR
  168.     PUSH    BP
  169.     MOV    BP,SP
  170.     MOV    BH,0        ; CURRENT PAGE NUMBER
  171.     MOV    AH,3        ; CURSOR POSITION FUNCTION NUMBER
  172.     INT    10H        ; VIDEO I/O INTERRUPT
  173.     MOV    AH,DH        ; MOVE INT RETURN INTO FUNCTION RETURN
  174.     MOV    AL,DL        ; DITTO
  175.     POP    BP
  176.     RET
  177. BIOSPOS    ENDP
  178. ;
  179. ; Scroll the screen up within a defined window.
  180. ;
  181. ; synopsis    biosup(numlines,trow,tlcol,brow,brcol,fchar);
  182. ;
  183. ;        int numlines;    number of lines to scroll up
  184. ;        int trow;    top row of window
  185. ;        int tlcol;    top left column of window
  186. ;        int brow;    bottom row of window
  187. ;        int brcol;    bottom right column of window
  188. ;        int fchar;    fill character of opened line
  189. ;
  190. ; note: numlines = 0 blanks entire window.  Upper left corner of full
  191. ;    screen is 0,0 while the bottom right corner of full screen is
  192. ;    24,79.
  193. ;
  194. BIOSUP    PROC    NEAR
  195.     PUSH    BP
  196.     MOV    BP,SP
  197.     MOV    AL,[BP+4]    ; NUMBER OF LINES TO SCROLL
  198.     MOV    CH,[BP+6]    ; TOP ROW OF WINDOW
  199.     MOV    CL,[BP+8]    ; TOP LEFT COLUMN OF WINDOW
  200.     MOV    DH,[BP+10]    ; BOTTOM ROW OF WINDOW
  201.     MOV    DL,[BP+12]    ; BOTTOM RIGHT COLUMN OF WINDOW
  202.     MOV    BH,[BP+14]    ; FILL CHARACTER
  203.     MOV    AH,6        ; SCROLL UP FUNCTION NUMBER
  204.     INT    10H        ; VIDEO I/O INTERRUPT
  205.     POP    BP
  206.     RET
  207. BIOSUP    ENDP
  208. ;
  209. ; Scroll the screen down within a defined window.
  210. ;
  211. ; synopsis    biosdwn(numlines,trow,tlcol,brow,brcol,fchar);
  212. ;
  213. ;        int numlines;    number of lines to scroll down
  214. ;        int trow;    top row of window
  215. ;        int tlcol;    top left column of window
  216. ;        int brow;    bottom row of window
  217. ;        int brcol;    bottom right column of window
  218. ;        int fchar;    fill character of opened line
  219. ;
  220. ; note: numlines = 0 blanks entire window.  Upper left corner of full
  221. ;    screen is 0,0 while the bottom right corner of full screen is
  222. ;    24,79.
  223. ;
  224. BIOSDWN    PROC    NEAR
  225.     PUSH    BP
  226.     MOV    BP,SP
  227.     MOV    AL,[BP+4]    ; NUMBER OF LINES TO SCROLL
  228.     MOV    CH,[BP+6]    ; TOP ROW OF WINDOW
  229.     MOV    CL,[BP+8]    ; TOP LEFT COLUMN OF WINDOW
  230.     MOV    DH,[BP+10]    ; BOTTOM ROW OF WINDOW
  231.     MOV    DL,[BP+12]    ; BOTTOM RIGHT COLUMN OF WINDOW
  232.     MOV    BH,[BP+14]    ; FILL CHARACTER
  233.     MOV    AH,7        ; SCROLL DOWN FUNCTION NUMBER
  234.     INT    10H        ; VIDEO I/O INTERRUPT
  235.     POP    BP
  236.     RET
  237. BIOSDWN    ENDP
  238. ;
  239. ; Read the contents of a given screen cell.
  240. ;
  241. ; synopsis    iret=biosrca();
  242. ;
  243. ;        int iret;    high order bits contain attributes
  244. ;                low order bits contain character
  245. ;
  246. ; NOTE - Attributes are defined on page 13-9 of the DOS v2.0 manual
  247. ;
  248. BIOSRCA    PROC    NEAR
  249.     PUSH    BP
  250.     MOV    BP,SP
  251.     MOV    BH,0        ; ACTIVE DISPLAY PAGE
  252.     MOV    AH,8        ; READ CHARACTER + ATTRIBUTES FUNCTION
  253.     INT    10H        ; VIDEO I/O INTERRUPT
  254.     POP    BP
  255.     RET
  256. BIOSRCA    ENDP
  257. ;
  258. ; Write a character to the screen - with attributes.
  259. ;
  260. ; synopsis    bioswca(char,count,att);
  261. ;
  262. ;        *** no value returned ***
  263. ;        int char;    character to output
  264. ;        int count;    number of times to output character
  265. ;        int att;    character attribute
  266. ;
  267. ; NOTE - Attributes are defined on page 13-9 of the DOS v2.0 manual
  268. ;
  269. BIOSWCA    PROC    NEAR
  270.     PUSH    BP
  271.     MOV    BP,SP
  272.     MOV    AL,[BP+4]    ; CHARACTER
  273.     MOV    CX,[BP+6]    ; NUMBER OF CHARACTERS TO WRITE
  274.     MOV    BL,[BP+8]    ; CHARACTER ATTRIBUTE
  275.     MOV    BH,0        ; ACTIVE DISPLAY PAGE
  276.     MOV    AH,9        ; WRITE CHARACTER/w ATTRIBUTES FUNCTION
  277.     INT    10H        ; VIDEO I/O INTERRUPT
  278.     POP    BP
  279.     RET
  280. BIOSWCA    ENDP
  281. ;
  282. ; Write a character to the screen - no attributes.
  283. ;
  284. ; synopsis    bioswc(char,count);
  285. ;
  286. ;        *** no value returned ***
  287. ;        int char;    character to output
  288. ;        int count;    number of times to output character
  289. ;
  290. BIOSWC    PROC    NEAR
  291.     PUSH    BP
  292.     MOV    BP,SP
  293.     MOV    AL,[BP+4]    ; CHARACTER
  294.     MOV    CX,[BP+6]    ; NUMBER OF CHARACTERS TO WRITE
  295.     MOV    BL,0;        ; CHARACTER ATTRIBUTE - NULL
  296.     MOV    BH,0        ; ACTIVE DISPLAY PAGE
  297.     MOV    AH,10        ; WRITE CHARACTER ONLY FUNCTION NUMBER
  298.     INT    10H        ; VIDEO I/O INTERRUPT
  299.     POP    BP
  300.     RET
  301. BIOSWC    ENDP
  302. ;
  303. ; Write a dot in graphics mode.
  304. ;
  305. ; synopsis    bioswd(irow,icol);
  306. ;
  307. ;        *** no value returned ***
  308. ;        int irow;
  309. ;        int icol;
  310. ;
  311. BIOSWD    PROC    NEAR
  312.     PUSH    BP
  313.     MOV    BP,SP
  314.     MOV    DX,[BP+4]    ; ROW
  315.     MOV    CX,[BP+6]    ; COLUMN
  316.     MOV    AL,1        ; GREEN COLOR
  317.     MOV    AH,12        ; WRITE A DOT FUNCTION NUMBER
  318.     INT    10H        ; VIDEO I/O INTERRUPT
  319.     POP    BP
  320.     RET
  321. BIOSWD    ENDP
  322. ;
  323. ; Write a character to the screen using the BIOS ascii teletype call.
  324. ; The teletype call will send cr/lf if column 79 is written to (0-79).
  325. ; It will scroll the screen up if row 24 (0-24) column 79 is written to.
  326. ; It will also beep the bell if ^g is received and provide a destructive
  327. ; backspace.
  328. ;
  329. ; synopsis    biostty(c);
  330. ;
  331. ;        char c;        character to write.
  332. ;
  333. BIOSTTY    PROC    NEAR
  334.     PUSH    BP
  335.     MOV    BP,SP
  336.     MOV    AL,[BP+4]    ; CHARACTER TO WRITE INTO AL
  337.     MOV    AH,14        ; TTY FUNCTION
  338.     MOV    BH,0        ; DISPLAY PAGE
  339.     INT    10H        ; BIOS VIDEO I/O INTERRUPT
  340.     POP    BP
  341.     RET
  342. BIOSTTY    ENDP
  343. ;
  344. ; Return the current video state of the screen.
  345. ;
  346. ; synopsis    iret = bioscur();
  347. ;
  348. ;        int iret;    low bits are the mode currently set
  349. ;                (see biosini for description)
  350. ;                high bits are the number of columns on screen
  351. ;
  352. BIOSCUR    PROC    NEAR
  353.     PUSH    BP
  354.     MOV    BP,SP
  355.     MOV    AH,15        ; CURRENT VIDEO STATE FUNCTION
  356.     INT    10H        ; BIOS VIDEO I/O INTERRUPT
  357.     POP    BP
  358.     RET
  359. BIOSCUR    ENDP
  360. ;
  361. ; *******************************************************************
  362. ;
  363. ;            *** communications port ***
  364. ;
  365. ; NOTE - the communications port I/O is described starting on page A-20
  366. ;        of the Tech Ref Manual.
  367. ;
  368. ; *******************************************************************
  369. ;
  370. ; Initialize the communications port.
  371. ;
  372. ; synopsis    iret = comini(port,params);
  373. ;
  374. ;        int iret;    return status (see comstat)
  375. ;        int port;    communications port to initialize (0,1)
  376. ;        int params;    bit pattern for initialization -
  377. ;
  378. ;    7    6    5    4    3    2    1    0
  379. ;       ------BAUD RATE ---     --PARITY--   STOP BIT   --WORD LENGTH--
  380. ;
  381. ;    000 - 110        X0 - NONE    0 - 1    10 - 7 BITS
  382. ;    001 - 150        01 - ODD    1 - 2    11 - 8 BITS
  383. ;    010 - 300        11 - EVEN
  384. ;    011 - 600
  385. ;    100 - 1200
  386. ;    101 - 2400
  387. ;    110 - 4800
  388. ;    111 - 9600
  389. ;
  390. COMINI    PROC    NEAR
  391.     PUSH    BP
  392.     MOV    BP,SP
  393.     MOV    DX,[BP+4]    ; COMM PORT TO INITIALIZE
  394.     MOV    AL,[BP+6]    ; PARAMETERS
  395.     MOV    AH,0        ; INITIALIZATION FUNCTION
  396.     INT    14H        ; COMM PORT I/O INTERRUPT
  397.     POP    BP
  398.     RET
  399. COMINI    ENDP
  400. ;
  401. ; Write a character to the communications port.
  402. ;
  403. ; synopsis    iret = comout(port,c);
  404. ;
  405. ;        int iret;    error return ( >127 if error occured)
  406. ;                - see AH under modem control
  407. ;        int port;    communications port to write (0 or 1)
  408. ;        int c;        character to write.
  409. ;
  410. COMOUT    PROC    NEAR
  411.     PUSH    BP
  412.     MOV    BP,SP
  413.     MOV    DX,[BP+4]    ; COMM PORT TO WRITE
  414.     MOV    AL,[BP+6]    ; CHARACTER TO WRITE
  415.     MOV    AH,1        ; WRITE CHARACTER FUNCTION
  416.     INT    14H        ; COMM PORT I/O INTERRUPT
  417.     POP    BP
  418.     RET
  419. COMOUT    ENDP
  420. ;
  421. ; Read a character from the communications port.  Waits for character if
  422. ; one is not ready.  See \comm\ibmtty.c for example of polling comm port
  423. ; for character without wait.
  424. ;
  425. ; synopsis    c = comin(port);
  426. ;
  427. ;        int c;        character read from comm port,
  428. ;                > 127 if error or no character ready.
  429. ;                - see AH under modem control
  430. ;        int port;    communications port to read (0 or 1)
  431. ;
  432. COMIN    PROC    NEAR
  433.     PUSH    BP
  434.     MOV    BP,SP
  435.     MOV    DX,[BP+4]    ; COMM PORT TO READ
  436.     MOV    AH,2        ; READ CHARACTER FUNCTION
  437.     INT    14H        ; COMM PORT I/O INTERRUPT
  438.     POP    BP
  439.     RET
  440. COMIN    ENDP
  441. ;
  442. ; Check the line and modem status
  443. ;
  444. ; synopsis    iret = comstat(port);
  445. ;
  446. ;        int iret;    ; line and modem status
  447. ;        AH - high order bits contain line control status
  448. ;        bit 7 = time out
  449. ;        bit 6 = trans shift register empty
  450. ;        bit 5 = trans holding register empty
  451. ;        bit 4 = break detect
  452. ;        bit 3 = framing error
  453. ;        bit 2 = parity error
  454. ;        bit 1 = overrun error
  455. ;        bit 0 = data ready
  456. ;
  457. ;        AL - low order bits contain modem status
  458. ;        bit 7 = received line signal detect
  459. ;        bit 6 = ring indicator
  460. ;        bit 5 = data set ready
  461. ;        bit 4 = clear to send
  462. ;        bit 3 = delta receive line signal detect
  463. ;        bit 2 = trailing edge ring detector
  464. ;        bit 1 = delta data set ready
  465. ;        bit 0 = delta clear to send
  466. ;
  467. ; Note - from page A-21 of Tech Ref Manual
  468. ;
  469. ;        int port;    ; communications port to check
  470. ;
  471. COMSTAT    PROC    NEAR
  472.     PUSH    BP
  473.     MOV    BP,SP
  474.     MOV    DX,[BP+4]    ; COMM PORT TO CHECK
  475.     MOV    AH,3        ; STATUS FUNCTION
  476.     INT    14H        ; COMM PORT I/O INTERRUPT
  477.     POP    BP
  478.     RET
  479. COMSTAT    ENDP
  480. ;
  481. ;**********************************************************************
  482. ;
  483. ;            *** io.asm ***
  484. ;
  485. ; IBM-PC 8088 assembly for interface with microsoft "C" under PC-DOS
  486. ;
  487. ; "C" callable subroutines that provide absolute pointer addressing.
  488. ; Pointers within a IBM-PC microsoft "C" program are relative to the
  489. ; start of the programs data segment.  These subroutines provide a
  490. ; mechanism to address absolute memory locations.
  491. ;
  492. ; Supplied by microsoft - commented by L. Cuthbertson, April 1984
  493. ;
  494. ;**********************************************************************
  495. ;
  496. ; Read an absolute memory location.
  497. ;
  498. ; synopsis    c = readabs(loc);
  499. ;
  500. ;        int c;        contents of memory location
  501. ;        int loc;    absolute memory location in hex
  502. ;
  503. INP    PROC    NEAR
  504.     PUSH    BP
  505.     MOV    BP,SP
  506.     MOV    DX,[BP+4]    ;GET LOCATION ADDRESS
  507.     IN    AL,DX        ;READ LOCATION
  508.     XOR    AH,AH        ;CLEAR HIGH BYTE
  509.     POP    BP
  510.     RET
  511. INP    ENDP
  512. ;
  513. ; Write an absolute memory location.
  514. ;
  515. ; synopsis    writeabs(loc,c);
  516. ;
  517. ;        int loc;    absolute memory location in hex
  518. ;        int c;        integer to write to memory location
  519. ;
  520. OUTP    PROC    NEAR
  521.     PUSH    BP
  522.     MOV    BP,SP
  523.     MOV    DX,[BP+4]    ;GET LOCATION ADDRESS
  524.     MOV    AX,[BP+6]    ;GET ADDRESS OF INTEGER TO WRITE
  525.     OUT    DX,AL        ;WRITE TO MEMORY LOCATION
  526.     POP    BP
  527.     RET
  528. OUTP    ENDP
  529. ;
  530. ;**********************************************************************
  531. ;
  532. PROG    ENDS
  533.     END
  534. ;
  535.  
  536.